{include file="public/header" /}
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">所属频道</label>
        <div class="layui-input-block">
            <select name="sex">
                <option value="2" {if isset($info.sex) && $info.sex eq 2}selected="selected"{/if}>男频</option>
                <option value="1" {if isset($info.sex) && $info.sex eq 1}selected="selected"{/if}>女频</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">上级分类</label>
        <div class="layui-input-block">
            <select name="pid">
                <option value="0">无</option>
                {if !empty($cate_list)}
                {foreach $cate_list as $cate}
                <option value="{$cate.id}" {if isset($info.pid) && $info.pid eq $cate.id}selected="selected"{/if}>{$cate.name}</option>
                {/foreach}
                {/if}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">分类名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="分类名称不能为空" value="{:isset($info['name']) ? $info.name: ''}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sort" placeholder="" value="{:isset($info['sort']) ? $info.sort: '99'}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">显示:</label>
        <div class="layui-input-block">
            <select name="status" id="status">
                <option value="1" {if isset($info.status) && $info.status eq 1}selected="selected"{/if}>是</option>
                <option value="0" {if isset($info.status) && $info.status eq 0}selected="selected"{/if}>否</option>
            </select>
        </div>
    </div>

    <input name="id" type="hidden" value="{:isset($info['id']) ? $info.id: ''}">
    <input name="type" type="hidden" value="{:$type}">

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "{:isset($info['id']) ? url('edit'):url('add')}",
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                timeout: 2000,
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg)
                        setTimeout(function () {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 1000);
                    } else {
                        layer.msg(res.msg)
                    }
                },
                error: function () {
                    layer.msg("添加失败")
                }
            })
            return false;
        });

    });
</script>
</body>
</html>